package Vista;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SpinnerListModel;
import javax.swing.SwingConstants;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import Controlador.Sistema;
import DAO.DAOAutomovil;
import DAO.DAOReserva;
import DAO.dtoAlquiler;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class frmDevolverAutomovil extends javax.swing.JFrame {
	private JScrollPane jScrollPane4;
	private JTable tblAlquileres;
	private ArrayList<dtoAlquiler> alquileres = new ArrayList<dtoAlquiler>();
	private JLabel lblComentarios;
	private JTextField txtReparaciones;
	private JLabel lblMontoReparaciones;
	private JTextField txtComentarios;
	private JButton btnDevolver;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				frmDevolverAutomovil inst = new frmDevolverAutomovil();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public frmDevolverAutomovil() {
		super();
		initGUI();
		llenarGrillaAlquileres();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jScrollPane4 = new JScrollPane();
				getContentPane().add(jScrollPane4);
				jScrollPane4.setBounds(12, 7, 742, 299);
				{
					TableModel tblReservasModel = 
						new DefaultTableModel(
								new String[][] { { "One", "Two" }, { "Three", "Four" } },
								new String[] { "Column 1", "Column 2" });
					tblAlquileres = new JTable();
					jScrollPane4.setViewportView(tblAlquileres);
					tblAlquileres.setModel(tblReservasModel);
					tblAlquileres.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
					tblAlquileres.setBounds(629, 186, 66, 44);
				}
			}
			{
				btnDevolver = new JButton();
				getContentPane().add(btnDevolver);
				btnDevolver.setText("Devolver Automovil");
				btnDevolver.setBounds(494, 333, 146, 45);
			}
			{
				txtComentarios = new JTextField();
				getContentPane().add(txtComentarios);
				txtComentarios.setBounds(12, 337, 289, 38);
			}
			{
				lblComentarios = new JLabel();
				getContentPane().add(lblComentarios);
				lblComentarios.setText("Comentarios");
				lblComentarios.setBounds(12, 315, 68, 16);
			}
			{
				lblMontoReparaciones = new JLabel();
				getContentPane().add(lblMontoReparaciones);
				lblMontoReparaciones.setText("Costos de reparaciones");
				lblMontoReparaciones.setBounds(328, 315, 143, 16);
			}
			{
				txtReparaciones = new JTextField();
				getContentPane().add(txtReparaciones);
				txtReparaciones.setText("0.00");
				txtReparaciones.setBounds(328, 337, 160, 38);
				txtReparaciones.setHorizontalAlignment(SwingConstants.RIGHT);
			}
			pack();
			this.setSize(786, 425);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	

	private void llenarGrillaAlquileres(){
		
		alquileres = Sistema.Getinstancia().obtenerAlquileres();
		
		DefaultTableModel tm = new DefaultTableModel();


		tm.addColumn("Inicio");
		tm.addColumn("Fin");
		tm.addColumn("Modelo");
		tm.addColumn("Estado");
		tm.addColumn("Vigencia");
		tm.addColumn("Limite tanque");
		tm.addColumn("Costo Alquiler");
		tm.addColumn("Costo Devolucion");
		tm.addColumn("Patente");
		
		
		for (dtoAlquiler da : alquileres) {
			Vector<String> valores = new Vector<String>();

			valores.add(da.getFechaInicio());
			valores.add(da.getFechaFin());
			valores.add(da.getTipoModelo());
			valores.add(da.getEstado());
			valores.add(da.getFechaVigencia());
			valores.add(da.getTanqueLimite());
			valores.add(da.getCostoAlquiler());
			valores.add(da.getCostoDevolucion());
			valores.add(da.getAutomovilPatente());
			
			tm.addRow(valores);
			
		}
		
		this.tblAlquileres.setModel(tm);
		
	}	
	
	
	

}
